package com.ssh.action;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.util.ValueStack;
import com.ssh.pojo.User;
import com.ssh.service.UserService;

public class UserAction extends ActionSupport {
	
	private static final long serialVersionUID = 1L;

	private User user;
	private UserService service;
	private Map param=new HashMap();

	public Map getParam() {
		return param;
	}
	public void setParam(Map param) {
		this.param = param;
	}
	public UserService getService() {
		return service;
	}
	public void setService(UserService service) {
		this.service = service;
	}
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	
	public String execute(){
		if (service.save(user)!=null) {
			return SUCCESS;
		}else {
			return ERROR;
		}
	}
	
	public String login(){
		Map<String, Object> session = ActionContext.getContext().getSession();
		HttpServletRequest request = ServletActionContext.getRequest();
		session.put("username", request.getParameter("username"));
		return SUCCESS;
	}
	public String listUser(){
		user=new User();
		user.setUsername("admin");
		param.put("status","登陆");
		return SUCCESS;
	}
}
